package com.rpsoftware.quickmart;

import java.util.ArrayList;
import java.util.Collection;

import com.google.zxing.client.android.Intents;
import com.google.zxing.client.android.R;
import com.google.zxing.client.android.R.layout;
import com.google.zxing.client.android.R.menu;
import com.google.zxing.client.android.CaptureActivity;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

/**
 * An example of how to call the barcodeReader and receive the result.
 * 
 * @author RP software
 *
 */
public class TestActivity extends Activity {
	
	static final int SCAN_BARCODE_REQUEST = 77;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_test);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		return true;
	}
	
	/**
	 * This method is called when you click the bottom
	 * @param view
	 */
	public void scanBarCode(View view){

		IntentIntegrator integrator = new IntentIntegrator(this);
		integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);

	}
	
	/**
	 * This method is called when you click the bottom
	 * @param view
	 */
	public void scanQrCode(View view){

		 IntentIntegrator integrator = new IntentIntegrator(this);
	     integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);

	}
	
	/**
	 * This method is called when you click the bottom
	 * @param view
	 */
	public void scanCode(View view){

		 IntentIntegrator integrator = new IntentIntegrator(this);
		 
		 Collection<String> codeFilter = new ArrayList<String>();
		 codeFilter.addAll(IntentIntegrator.PRODUCT_CODE_TYPES);
		 codeFilter.addAll(IntentIntegrator.QR_CODE_TYPES);
		 
	     integrator.initiateScan(codeFilter);



	}
	
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data){
		
		IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
	    if (result != null) {
	      String contents = result.getContents();
	      if (contents != null) {
	    	  
	    	  String format = data.getStringExtra(Intents.Scan.RESULT_FORMAT);
	    	  EditText editText = (EditText) findViewById(R.id.editText1);
	    	  editText.setText(format + ": " + contents.toString());
	      } 
	    }

		
	}
	
}
